package org.hotswap.agent.plugin.spring.getbean.cglib;

import org.hotswap.agent.plugin.spring.getbean.DetachableBeanHolder;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;


public class HotswapSpringCallback extends DetachableBeanHolder implements MethodInterceptor {

    @Override
    public Object intercept(Object var1, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        if (method != null
                && "finalize".equals(method.getName())
                && method.getParameterTypes().length == 0) {
            return null;
        } else if (method != null
                && "$$ha$getTarget".equals(method.getName())) {
            return this.getTarget();
        } else if (method != null
                && "$$ha$setTarget".equals(method.getName())) {
            this.setTarget(args[0]);
            return null;
        } else {
            return methodProxy.invoke(this.getBean(), args);
        }
    }

    public HotswapSpringCallback(Object bean, Object beanFactory, Class[] paramClasses, Object[] paramValues) {
        super(bean, beanFactory, paramClasses, paramValues);
    }
}
